package com.fr.report.web.ui.impl.form;

import com.fr.base.ArrayUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.core.list.IntList;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.cellElement.Formula;
import com.fr.report.js.JavaScript;
import com.fr.report.js.JavaScriptImpl;
import com.fr.report.parameter.Parameter;
import com.fr.report.web.event.DefaultListener;
import com.fr.report.web.event.Listener;
import com.fr.report.web.ui.Button;
import com.fr.web.Repository;
import java.util.List;

public class TreeNodeToogleButton extends Button
{
  private boolean initExpanded = false;
  private Listener default_listener;
  private static final String SON_RANGE_INDEXLIST = "$$son_range_indexlist_container";

  public TreeNodeToogleButton()
  {
    if (VT4FR.COLLAPSABLE_TREE_VIEW.support())
    {
      JavaScriptImpl localJavaScriptImpl = new JavaScriptImpl("this.options.sonarray = $$son_range_indexlist_container;this._node_init();");
      localJavaScriptImpl.setParameters(new Parameter[] { new Parameter("$$son_range_indexlist_container", new Formula("=$$son_range_indexlist")) });
      this.default_listener = new DefaultListener("afterinit", localJavaScriptImpl);
    }
  }

  public boolean isInitExpanded()
  {
    return this.initExpanded;
  }

  public void setInitExpanded(boolean paramBoolean)
  {
    this.initExpanded = paramBoolean;
  }

  public String getXType()
  {
    return "treenode";
  }

  public IntList getRelativeIndexList()
  {
    JavaScript localJavaScript = this.default_listener.getAction();
    Parameter[] arrayOfParameter = localJavaScript.getParameters();
    if (arrayOfParameter.length > 0)
    {
      Object localObject = arrayOfParameter[0].getValue();
      if (localObject instanceof Formula)
        localObject = ((Formula)localObject).getResult();
      if (localObject instanceof IntList)
        return ((IntList)localObject);
    }
    return null;
  }

  public Listener getListener(int paramInt)
  {
    if (paramInt == 0)
      return this.default_listener;
    return ((this.listenerList == null) ? null : (Listener)this.listenerList.get(paramInt - 1));
  }

  public int getListenerSize()
  {
    return ((this.listenerList == null) ? 1 : this.listenerList.size() + 1);
  }

  public Listener[] createListeners(Repository paramRepository)
  {
    return ((Listener[])ArrayUtils.addAll(super.createListeners(paramRepository), new Listener[] { this.default_listener }));
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    if (this.initExpanded)
      localJSONObject.put("expand", isInitExpanded());
    return localJSONObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("InitExpanded"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getElementValue()) != null)
          setInitExpanded(new Boolean(str2).booleanValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (isInitExpanded())
      paramXMLPrintWriter.startTAG("InitExpanded").textNode(String.valueOf(isInitExpanded())).end();
  }

  public boolean equals(Object paramObject)
  {
    if ((paramObject == null) || (!(paramObject instanceof TreeNodeToogleButton)))
      return false;
    TreeNodeToogleButton localTreeNodeToogleButton = (TreeNodeToogleButton)paramObject;
    return ((super.equals(paramObject)) && (this.initExpanded == localTreeNodeToogleButton.initExpanded));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    TreeNodeToogleButton localTreeNodeToogleButton = (TreeNodeToogleButton)super.clone();
    localTreeNodeToogleButton.default_listener = ((Listener)this.default_listener.clone());
    return localTreeNodeToogleButton;
  }
}